import httplib, urllib, time, sys

SERVER = "10.1.1.100:7775"

class Client:

    def __init__(self, data, file_size):
        self.data = data
        self.conn = httplib.HTTPConnection(SERVER)
        self.conn.connect()
        self.file_size = file_size
        
    def ReadFile(self, filenum):
    
        headers = {"Content-type": "text/plain", "Connection": "Keep-Alive"}
        filename = "/index%s%d.html" % (self.file_size, filenum)
        self.conn.request("GET", filename, "", headers)
        response = self.conn.getresponse()
        sum = int(response.getheader("Content-Length"))
        dummy_data = response.read()
        sum = 0
        return sum
    
    def run(self):
        bytes = 0
        requests = 0
        start_time = time.time()
        end_time = start_time
        
        while (end_time - start_time < 5):
            for i in range(0,12):
                bytes += self.ReadFile(i)
                end_time = time.time()
                requests += 1
        self.conn.close()
        self.data.updateRateTotal(bytes / (end_time - start_time), requests / (end_time - start_time))
        
class Data:

    def __init__(self):
        self.rate = 0
        self.requests = 0

    def updateRateTotal(self, new_rate, requests):
        self.rate += new_rate
        self.requests += requests

    def printData(self):
        # output = open(self.filename, 'w')
        # output.write("%.02f\n%.02f\n"%((self.rate * 8 / 1024 / 1024),(self.requests / 1000)))
        print "%.02f"%(self.requests / 1000)
        
if __name__ == '__main__':

    data = Data()

    file_size = sys.argv[2]

    client = Client(data, file_size)
    client.run()

    data.printData()
        



    
